package com.tedu.springmvc.controller;


import com.tedu.springmvc.mapper.UserInfoMapper;
import com.tedu.springmvc.pojo.dto.UserDTO;
import com.tedu.springmvc.pojo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class UserController {
    @Autowired
    UserInfoMapper mapper;
//    @RequestMapping("/regUser")
//    @ResponseBody
//    public String reg(HttpServletRequest request){
//        String username = request.getParameter("username");
//        String password = request.getParameter("password");
//        String nickname = request.getParameter("nickname");
//        String age = request.getParameter("age");
//        System.out.println("username="+username+",password="+password+",nickname="+nickname+",age="+age);
//        System.out.println("开始处理用户注册操作");
//        return "注册成功";
//    }
//    @RequestMapping("/regUser")
//    @ResponseBody
//    public String reg(String username,String password,String nickname,int age){
//        System.out.println(username+" "+password+" "+nickname+" "+age);
//        return "注册成功";
//    }
    @RequestMapping("/regUser")
    @ResponseBody
    public String reg(UserDTO user){
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(user.getUsername());
        userInfo.setPassword(user.getPassword());
        userInfo.setNickname(user.getNickname());
        userInfo.setAge(user.getAge());
        return (mapper.insertUser(userInfo)>0?"注册成功!":"注册失败!");
    }
}
